<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.context.*"%>
<%@ page import="com.gzgi.framework.resource.*"%>
<%@ page import="com.gzgi.framework.config.*"%>
<%@ page import="net.sf.jxls.transformer.*"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="com.gzgi.workflow.jbpm.model.Product"%>
<%
        SqlMapManager sqlMapManager = (SqlMapManager)ContextFactory.getBean("sqlMapManager");
	    Executor queryExecutor = new Executor();
        queryExecutor.setQuery("getAllProduct");
		long start = System.currentTimeMillis();
	    List rows = sqlMapManager.getList(1, 5000, queryExecutor);
		System.out.println("query time(ms):" + (System.currentTimeMillis() - start));
		System.out.println("##############################");
	    Map dataMap = new HashMap();
	    dataMap.put("list", rows);

        String templateFileName = MessageProperties.getConfigRootPath()+ "/config/templates/excel/productList5.xls";
        FileInputStream fin = new FileInputStream(templateFileName);

        start = System.currentTimeMillis();
		XLSTransformer transformer = new XLSTransformer();
		HSSFWorkbook wb = transformer.transformXLS(fin, dataMap);

		byte[] bytes = null;
		if (wb != null) {
			try {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				BufferedOutputStream bos = new BufferedOutputStream(baos);
				wb.write(bos);
				bos.close();
				baos.close();
				bytes = baos.toByteArray();
				bos.close();
				baos.close();
			} catch (IOException ex) {
			}
		}

		System.out.println("process excel time(ms):" + (System.currentTimeMillis() - start));

		response.reset();
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment; filename=export.xls");
		OutputStream outputStream = response.getOutputStream();
		outputStream.write(bytes);
		outputStream.flush();
		outputStream.close();
		bytes = null;
 %>